package com.atguigu.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Cart {
    private List<CartItem> items = new ArrayList<>();
    private Integer countNum; //商品数量
    private Integer countType; //商品类型数量
    private BigDecimal totalAmount; //商品总价
    private BigDecimal reduce = BigDecimal.ZERO; //减免价格,先默认设为0

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int num = 0;
        if (items != null && items.size() >0){
            for (CartItem item : items) {
                num += item.getCount();
            }
        }
        return num;
    }

    public Integer getCountType() {
        return items.size();
    }


    public BigDecimal getTotalAmount() {
        BigDecimal result = BigDecimal.ZERO;
        if (items != null && items.size() >0){
            for (CartItem item : items) {
                if (item.getCheck() == true){
                    result = result.add(item.getTotalPrice());
                }
            }
            result = result.subtract(reduce);
        }
        return result;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
